
<style>

    .layui-btn{

        width: 80px;
    }

     .layui-input-block {
         margin-left: 0px;
         width: 300px;
         display: inline-block;
     }
    .layui-form-label {
        width: 120px;
    }

</style>
<div style="margin: 5% 5%">
<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form-item" style="display: none">
        <div class="layui-input-block">
            <input type="text" name="groupId" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="display: none">
        <div class="layui-input-block">
            <input type="text" name="oldGroupName" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">分组名称:</label>
        <div class="layui-input-block">
            <input type="text" name="groupName" lay-verify="title" autocomplete="off" placeholder="请输入分组名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分组状态:</label>
        <div class="layui-input-block">
            <select name="groupStatus">
                <option value="启用">启用</option>
                <option value="禁用">禁用</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <div style="margin-left: 120px;width: 300px">
                <button type="submit" class="layui-btn" lay-submit="updateEvent" lay-filter="updateEvent">修改</button>
                <a style="float: right"><button type="button" class="layui-btn layui-btn-normal" id="quxiao" lay-event="quxiaoEvent">取消</button></a>
            </div>
        </div>
    </div>

</form>
</div>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
<script>


        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        form.render();

        form.on("submit(updateEvent)", function (obj) {

            var getdata = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            $.ajax({
                url:"/admin/group/update/groupById",
                type:"put",
                dataType:"JSON",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(obj.field,obj.group_Name),
                // beforeSend: function () {
                //     this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
                // },
                success:function (res) {
                    console.log(res)
                    if (res.code==200){
                        layer.msg("修改成功",{icom:5,time: 1000}
                            ,function () {
                                localStorage.removeItem('group_Id')
                                localStorage.removeItem('group_Name')
                                location='#/exception/404';
                            }) ; //失败的表情
                        return ;
                    } else if(res.code==500){
                        layer.msg("修改失败",{
                            icon:4,  //失败的表情
                            time:1000 //2秒关闭
                        });
                    }
                },
                error:function () {
                    layer.msg("网络原因修改失败",{
                        icon:2,time: 1000
                    })
                },
                complete:function () {
                    layer.close(this.layerIndex);
                }
            })
            return false;
        });

    // var lay_group_id= getCookie("lay_group_id");
    //
    // $("input[name='groupId']").val(lay_group_id);
    //
    // function getCookie(cookieName){
    //     var cookieStr = unescape(document.cookie);
    //     var arr = cookieStr.split("; ");
    //     var cookieValue = "";
    //     for(var i=0;i<arr.length;i++){
    //         var temp = arr[i].split("=");
    //
    //         if(temp[0]==cookieName){
    //             cookieValue = temp[1];
    //             console.log("cookieValue"+cookieValue)
    //
    //             break;
    //         }
    //     }
    //     // 改分组下的所有终端
    //     return cookieValue;
    // }
    var grouplocak=localStorage.getItem('group_Id');
    var oldGroupName=localStorage.getItem('group_Name');
    var oldGroupStatus=localStorage.getItem('group_status');
    $("input[name='groupId']").val(grouplocak);
    $("input[name='groupName']").val(oldGroupName);
    $("select[name='groupStatus']").val(oldGroupStatus);

    $("#quxiao").click(function () {
        localStorage.removeItem('group_Id')
        location='#/exception/404';
    })

</script>